<?php
class Zendvn_View_Helper_CmsSelect extends Zend_View_Helper_Abstract{
	
	function cmsSelect($name,$value = NULL,$arrSource,$options=array()){
		
		if(count($arrSource)>0){
			//Kiem tra dieu kien options
			$strOptions='';
			if(count($options)>0){
				foreach ($options as $k=>$v){
					$strOptions.= $k . '="'.$v.'"';
				}
			}
			//Viet Selectbox
			$xhtml = '<select name = "'.$name.'" id="'.$name.'"'.$strOptions . '>';
			foreach ($arrSource as $key => $info){
				//Kiem tra dieu kien Selected
				$strSelected = '';
				if($info['id'] == $value){
						$strSelected = 'selected="selected"';
				}
				if($info['level']==1){
					$xhtml.='<option value ="'.$info['id'].'" '.$strSelected.'>+ '.$info['name'].'</option>';	
				}else{
					$string = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
					$newString = '';
					for($i=1;$i<$info['level']; $i++){
						$newString .= $string;
					}
					$info['name'] = $newString . '-' . $info['name'];
					$xhtml.='<option value ="'.$info['id'].'" '.$strSelected.'>'.$info['name'].'</option>';	
				}
			}
			$xhtml.= '</select>';
		}
		
		//Tra ve ket qua
		return $xhtml;
	}
}